package map;


import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * map 的遍历方式
 */
public class MapDemo2 {

    public static void main(String[] args) {

        Map<String, String> map = new HashMap<>();
        String value = map.put("name","上邪");
        map.put("age","22");
        map.put("hobby","lol");
        map.put("nick","vex");
        System.out.println(map);

        Set<String> keySet = map.keySet();
        for (String key: keySet) {
//            System.out.println(key);
        }

        Set<Map.Entry<String, String>> entries = map.entrySet();
//        System.out.println(entries);
        for (Map.Entry<String,String> entry : entries){
            System.out.println(entry.getKey()+ "," +entry.getValue());
        }

        Collection<String> values = map.values();
//        System.out.println(values);
//        for ( String v1:values){
//            System.out.println(v1);
//        }
//
//        values.forEach(
//                e -> System.out.println(e)
//        );
        map.forEach(
                (k,v)-> System.out.println(k+":"+v)
        );

    }
}
